package com.example.houtai.controller;


import com.baomidou.mybatisplus.extension.service.IService;
import com.example.houtai.config.Logger;
import com.example.houtai.entity.SysMenu;
import com.example.houtai.service.ISysMenuService;
import com.github.pagehelper.PageInfo;

import com.org.dto.MenuDto;
import com.org.vo.ResultEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * <p>
 * 菜单管理 前端控制器
 * </p>
 *
 *
 */
@RestController
@RequestMapping("/sys/menu")
public class SysMenuController {

    //满亨炜


    @Autowired
    private ISysMenuService sysMenuService;

    //    @Logger("菜单列表")
    @RequestMapping("list")
    public ResultEntity list() {
        List<SysMenu> list = sysMenuService.selectMenu();
        return ResultEntity.ok("200", "查询成功", list);
    }

    @RequestMapping("save")
    public ResultEntity save(@RequestBody MenuDto menuDto) {
        SysMenu menu = new SysMenu();
        BeanUtils.copyProperties(menuDto, menu);
        sysMenuService.save(menu);
        return ResultEntity.ok("添加成功");
    }
    //com.example.houtai.controller.SysMenuController.update

    /**
     * com.example.houtai.controller.SysMenuController#update(com.org.dto.MenuDto)
     * arthas command copied to clipboard,open arthas to execute command
     * watch com.example.houtai.controller.SysMenuController update '{params,returnObj,throwExp}'  -n 5  -x 3
     */


    @RequestMapping("update")
    public ResultEntity update(@RequestBody MenuDto menuDto) {
        SysMenu menu = new SysMenu();
        BeanUtils.copyProperties(menuDto, menu);
        menu.setMenuId(menu.getMenuId());
        sysMenuService.updateById(menu);
        return ResultEntity.ok("修改成功");
    }

    @RequestMapping("delete")
    public ResultEntity delete(@RequestParam("ids") Integer[] ids) {
        for (Integer id : ids) {
            System.out.println(id);
        }
        sysMenuService.removeByIds(Arrays.asList(ids));
        return ResultEntity.ok("删除成功");
    }

    @RequestMapping("rolemenuList")
    public ResultEntity list(@RequestParam("username") String username) {
        System.out.println(username);
        return ResultEntity.ok("200", "success", sysMenuService.rolemenuList(username));
    }
}
